package com.zly.bscloud.controller;

import com.zly.bscloud.dto.ArticleDTO;
import com.zly.bscloud.dto.PreferencesDTO;
import com.zly.bscloud.service.PreferencesService;
import com.zly.bscloud.utils.entity.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author zhouxiaoyu
 * @Date 2020/5/5 11:30
 * @Version 1.0
 */
@RestController
@RequestMapping("/recommend")
@Api(tags = "推荐接口")
@CrossOrigin
public class PreferencesController {
    @Autowired
    private PreferencesService preferencesService;
    @GetMapping("/hello")
    public String hello(){
        return "hell000999";
    }

    @PostMapping("/save-like")
    public Result saveLikeByUId(@RequestBody Map<String , String> map){
        PreferencesDTO preferencesDTO = preferencesService.saveLikeByUId(map);
        return Result.createSuccess(preferencesDTO);
    }

    @GetMapping("/get-like/{user_id}/{article_id}")
    public Result getLike(@PathVariable("user_id") String user_id,
                                  @PathVariable("article_id") String article_id){
        System.out.println(user_id);
        System.out.println(article_id);
        Boolean islike = preferencesService.getLike(user_id,article_id);
        return Result.createSuccess(islike);
    }

    @GetMapping("/get-recommendationList/{user_id}")
    public Result getRecommendationList(@PathVariable("user_id") String user_id){
        List<ArticleDTO> articleDTOList = preferencesService.getRecommendationList(user_id);
        return Result.createSuccess(articleDTOList);
    }
}
